public class test {
    class ArrayStack {
        private int[] stack;
        private int top;
        private int capacity;

        public ArrayStack(int capacity) {
            this.capacity = capacity;
            this.stack = new int[capacity];
            this.top = -1;
        }

        public boolean isEmpty() {
            return top == -1;
        }

        public boolean isFull() {
            return top == capacity - 1;
        }

        public void push(int item) {
            if (isFull()) {
                System.out.println("栈已满，无法入栈");
                return;
            }
            stack[++top] = item;
        }

        public int pop() {
            if (isEmpty()) {
                System.out.println("栈为空，无法出栈");
                return -1;
            }
            return stack[top--];
        }

        public int peek() {
            if (isEmpty()) {
                System.out.println("栈为空，没有栈顶元素");
                return -1;
            }
            return stack[top];
        }

        public static void main(String[] args) {
            ArrayStack stack = new ArrayStack(5);
            stack.push(1);
            stack.push(2);
            stack.push(3);
            System.out.println(stack.pop());
            System.out.println(stack.peek());
        }
    }
}
